<template>
  <div class="newcomer">
    <x-header :left-options="{backText: ''}">领取优惠券</x-header>
    <div class="couponList">
      <ul>
        <li class="fr" v-for="packet in packetList" @click="receivePacket(packet,packet.statu)">
          <a :href="packet.href">
            <div class="fa whiteColor couponMethod">
              ¥{{packet.name}}
            </div>
            <img src="../../assets/usCouponBg.png" alt="" v-if="packet.statu">
            <img src="../../assets/couponBg.png" alt="" v-if="!packet.statu">
          </a>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
  import { XHeader } from 'vux'
  import http from '../../service/http.js'
  import tips from '../../service/tips.js'
  import util from '../../service/util.js'
  export default {
    data() {
      return {
        packetList: [],
        username: "",
        isHref: ""
      }
    },
    mounted() {
      this.username = this.$route.query.username || util.getItem('login.username');
      // if (this.$route.query.username) {
      //   this.isHref = "coupons://tonative/param?id=packet"
      // } else {
      //   this.isHref = '#/main/coupon'
      // }
      this.packet();
    },
    methods: {
      receivePacket(packet, status) {
        // if (packet.status == 1) {
        if (status) {
          return false;
          this.isHref = '#/main/newcomer'
        }
        http.put("/user/packet?username=" + this.username, {
          type: packet.type,
          username: this.$route.query.username || util.getItem("Authorization")
        }).then((res) => {
          if (res.status == 200) {
            tips.tips(res.data.msg);
            this.packet();
          } else {
            tips.tips(res.data.msg);
          }
        }).catch((res) => {
          tips.tips(res.data.msg);
        })
        // }
      },
      packet() {
        http.get("/user/activitys/packet?id=packet&username=" + this.username).then((res) => {
          if (res.status == 200) {
            this.packetList = res.data.body;
            res.data.body.forEach(v => {
              if (v.statu && this.$route.query.username) {
                v.href = 'coupons://tonative/param?id=packet';
                return false;
              }
              if (v.statu) {
                v.href = '#/main/coupon';
                return false;
              }
            })
          }
        })
      }
    },
    components: {
      XHeader
    }
  }
</script>
<style lang="less">
  .newcomer .vux-header {
    background: #fff;
  }

  .newcomer {
    width: 100%;
    height: 953px;
    background-image: url('../../assets/newcomer.png');
    background-size: 100% 100%;
    background-position: center 0;
  }

  body {
    background: #fff;
  }

  .c6 {
    color: #666;
  }

  .c9 {
    color: #999;
  }

  .fr {
    position: relative;
  }

  .fa {
    position: absolute;
  }

  .whiteColor {
    color: #fff;
  }

  .couponMoneyBox {
    margin-left: 70px;
    margin-top: 8px;
  }

  .couponMethod {
    top: 32px;
    left: 60px;
  }

  .couponMoney {
    font-size: 39px;
  }

  .couponIcon {
    position: absolute;
    top: 10px;
    left: -9px;
  }

  .getItNow {
    color: #fff;
    width: 20px;
    font-size: 10px;
    text-align: center;
    margin-left: 18px;
    margin-top: 3px;
  }

  .newcomer .vux-header .vux-header-left .left-arrow:before {
    content: "";
    position: absolute;
    width: 12px;
    height: 12px;
    border: 1px solid #000;
    border-width: 1px 0 0 1px;
    -webkit-transform: rotate(315deg);
    transform: rotate(315deg);
    top: 8px;
    left: 7px;
  }

  .newcomer .vux-header .vux-header-title {
    line-height: 40px;
    text-align: center;
    font-size: 18px;
    font-weight: 400;
    color: #000;
  }

  .couponList {
    margin-top: 200px;
  }

  .couponList li {
    list-style: none;
    text-align: center;
  }

  .couponList li img {
    width: 95%;
  }
</style>